home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / Libraries / SAT 2.3b4 / Misc / SATminimalX ƒ / sMySprite.p < prev   
Text File  |  1994-08-23  |  2KB  |  65 lines

  1. {The sprite unit for SATminimal}
  2.  
  3. unit sMySprite;
  4.  
  5. interface
  6.     uses
  7.         SAT, FaceSetFromPICT;
  8.     var
  9.         theSound: Handle;
  10.         faces: array[0..5] of FacePtr;
  11.  
  12.     procedure InitMySprite;
  13.     procedure SetupMySprite (me: SpritePtr);
  14.     procedure HandleMySprite (me: SpritePtr);
  15.  
  16. implementation
  17.  
  18.     procedure MyFaceHandler (theFace: FacePtr; index: integer);
  19.     begin
  20.         faces[index - 2] := theFace;
  21.     end;
  22.  
  23. {Initialization of variables used by the sprite unit}
  24.     procedure InitMySprite;
  25.         var
  26.             i: integer;
  27.     begin
  28. {Preload the sound}
  29.         theSound := SATGetSound(128);
  30. {Preload all icons used by the sprites - 6 of them}
  31.         GetFaceSetFromPICT(128, 130, 131, 132, @MyFaceHandler);
  32. {for i := 0 to 5 do}
  33. {faces[i] := SATGetFace(128 + i);}
  34.     end;
  35.  
  36. {Initialize a new sprite}
  37.     procedure SetupMySprite (me: SpritePtr);
  38.     begin
  39.         me^.mode := 0;                    {Pick a valid face number}
  40.         me^.speed.h := 2;                    {Set the speed - only horizontal is used here }
  41.         me^.task := @HandleMySprite;    {Set a handling routine. MANDATORY! If nil, the sprite will self-destruct.}
  42.     end;
  43.  
  44. {Define the behaviour of a sprite}
  45.     procedure HandleMySprite (me: SpritePtr);
  46.     begin
  47. {Select a face. We use me^.mode as face counter, rotating through them.}
  48.         me^.mode := (me^.mode + 1) mod 6;
  49.         me^.face := faces[me^.mode];
  50.  
  51. {Move}
  52.         me^.position.h := me^.position.h + me^.speed.h; {Add the speed - horizontal only}
  53.         if me^.position.h > gSAT.offSizeH - 16 then {Turn back if at the right border}
  54.             begin
  55.                 me^.speed.h := -2;
  56.                 SATSoundPlay(theSound, 1, true);
  57.             end;
  58.         if me^.position.h < -16 then {Turn back if at the left border}
  59.             begin
  60.                 me^.speed.h := 2;
  61.                 SATSoundPlay(theSound, 1, true);
  62.             end;
  63.     end;
  64.  
  65. end.